/**
 * Copyright ©2012-2018 HopeHaiyang Corporation, All Rights Reserved
 * http://www.wuhanhope.com
 */
package hope.platform.data.server.data.img;

import hope.platform.data.dao.WarningRepository;
import hope.platform.data.domain.Warning;
import hope.platform.data.server.data.header.WarningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * class info
 *
 * @author hujia
 *         Create at 2018/7/20 16:07
 */
@Service
public class WarningServiceImg implements WarningService {

    @Autowired
    private WarningRepository repository;

    @Override
    public Warning addWarning(Warning warning) {
        warning.setGmtCreate(new Date());
        warning.setGmtModified(new Date());
        return repository.save(warning);
    }

    @Override
    public Warning findById(String id) {
        return repository.findById(id).get();
    }

    @Override
    public List<Warning> findBySerialNumber(String serialNumber) {
        return repository.findBySerialNumber(serialNumber);
    }

    @Override
    public List<Warning> findAll() {
        return repository.findAll();
    }

    @Override
    public List<Warning> getByGmtCreateBetween(Date beginTime, Date endTime) {
        return repository.findByGmtCreateBetween(beginTime,endTime);
    }

    @Override
    public Warning getTopBySerialNumberAndDataNameOrderByGmtCreateDesc(String serialNumber, String dataName) {
        return repository.findTopBySerialNumberAndDataNameOrderByGmtCreateDesc(serialNumber, dataName);
    }

    @Override
    public long countBySerialNumberAndDataNameAndGmtCreateBetween(
            String serialNumber, String dataName, Date beginTime, Date endTime) {
        return repository.countBySerialNumberAndDataNameAndGmtCreateBetween(
                serialNumber, dataName, beginTime, endTime);
    }
}
